package src.jeu;

import java.util.Vector;

public class Hanoi {

	private Vector towers;
	private int hitNb;
	
	public Hanoi(int diskNb, int towerNb) {
		this.towers = new Vector();
		this.hitNb=0;
		for(int i=0; i<towerNb; i++){
			this.towers.add(new Tower(diskNb));
		}
		for(int i=diskNb; i>0; i--){
			getTower(0).push(new Disk(i));
		}
	}
	
	private void fillsTower(int i){
		//??????????????????????????
	}
	
	public Tower getTower(int index){
		if (index>=0 && index<towers.size())
		return (Tower)this.towers.get(index);
		else return null;
	}
	
	public void moveDisk(int numTower1, int numTower2){
		//if ... verifier ...
		Disk disk1 = getTower(numTower1).getTopDisk();
		Disk disk2 = getTower(numTower2).getTopDisk();
		if(disk1 != null){
			if (disk2==null){
				getTower(numTower2).push(getTower(numTower1).pop());
				this.hitNb++;
			}
			else if(disk1.compareTo(disk2)<0){
					getTower(numTower2).push(getTower(numTower1).pop());
					this.hitNb++;
				}
				else
					System.out.println("pasPossible");
		}
		else System.out.println("Aie !!");
	}
	
	public void moveDisks(int nbDisks, int numTower1, int numTower2){
		//??????????????????????????
	}
	
	public void play(){
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(0, 2);System.out.println(toString());
		moveDisk(1, 2);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(2, 0);System.out.println(toString());
		moveDisk(2, 1);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(0, 2);System.out.println(toString());
		moveDisk(1, 0);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(1, 2);System.out.println(toString());
		moveDisk(1, 0);System.out.println(toString());
		moveDisk(2, 0);System.out.println(toString());
		moveDisk(1, 2);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(0, 2);System.out.println(toString());
		moveDisk(1, 2);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(2, 0);System.out.println(toString());		
		moveDisk(2, 1);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(2, 0);System.out.println(toString());
		moveDisk(1, 2);System.out.println(toString());
		moveDisk(1, 0);System.out.println(toString());
		moveDisk(2, 0);System.out.println(toString());
		moveDisk(2, 1);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(0, 2);System.out.println(toString());
		moveDisk(1, 2);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
		moveDisk(2, 0);System.out.println(toString());
		moveDisk(2, 1);System.out.println(toString());
		moveDisk(0, 1);System.out.println(toString());
	}
	
	public String toString(){
		String resultat = "Hanoi["+towers.size()+"]    "+this.hitNb;
		for (int i=0; i<towers.size(); i++) {
			resultat += "\n   I "+getTower(i).toString().replaceAll("\n", "\n   ");
		}
		return resultat;
	}
	
	public static void main(String[] args) {
		Hanoi h = new Hanoi(5, 3);System.out.println(h.toString());
		h.play();
		System.out.println("Victoire !!!");
	}
}
